package hashTable;

import java.awt.EventQueue;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.SwingConstants;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import javax.swing.JFormattedTextField;
import javax.swing.JTextField;
import javax.swing.JCheckBox;
import java.awt.event.ItemListener;
import java.awt.event.ItemEvent;
import javax.swing.JComboBox;

public class Main implements ActionListener {

	private JFrame frame;
	IHashTable hashTable;
	HashPicture hPicture;
	JLabel hstate;
	JFormattedTextField formattedTextField;
	private JFormattedTextField formattedTextField_1;
	private JFormattedTextField formattedTextField_2;
	private JFormattedTextField formattedTextField_3;
	private JFormattedTextField formattedTextField_4;
	private JFormattedTextField formattedTextField_5;
	private JLabel lblVon;
	private JLabel lblBis;
	private JTextField textField;
	private JLabel lblFllungsgrad;
	private JTextField textField_1;
	private JTextField textField_2;
	private JLabel lblCluster;
	private JTextField textField_3;
	private JLabel lblKollisionen;
	private JFormattedTextField formattedTextField_6;
	private JButton btnSuchen;
	private JTextField textField_4;
	private JFormattedTextField formattedTextField_7;
	private JFormattedTextField formattedTextField_8;
	private JFormattedTextField formattedTextField_9;
	private JFormattedTextField formattedTextField_10;
	private JFormattedTextField formattedTextField_11;
	private JFormattedTextField formattedTextField_12;
	private JFormattedTextField formattedTextField_13;
	private JFormattedTextField formattedTextField_14;
	private JFormattedTextField formattedTextField_15;
	private JFormattedTextField formattedTextField_16;
	private JFormattedTextField formattedTextField_17;
	private JFormattedTextField formattedTextField_18;
	private JComboBox<String> comboBox;
	private JFormattedTextField formattedTextField_19;
	private JFormattedTextField formattedTextField_20;
	private JFormattedTextField formattedTextField_21;
	private JFormattedTextField formattedTextField_22;
	private JFormattedTextField formattedTextField_23;
	private JFormattedTextField formattedTextField_24;
	private JFormattedTextField formattedTextField_25;
	private JFormattedTextField formattedTextField_26;
	private JFormattedTextField formattedTextField_27;
	private JButton btnSetb;
	private JLabel lblMax;
	
	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					Main window = new Main();
					window.frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the application.
	 */
	public Main() {
		initialize();
	}
	
	public void actionPerformed(ActionEvent e) {
		if (e.getActionCommand().equals("plus1")) {
			int koll = hashTable.add(Integer.parseInt(formattedTextField.getText()));
//			tHash.addRange(5,10);
			textField.setText(hashTable.getSize()+"");
			textField_1.setText(hashTable.getFuellGrad());
			textField_2.setText(hPicture.getClusterNumber()+"");
			textField_3.setText(koll+"");
		  	ImageIcon icon = hPicture.getImageIcon();
	    	icon.getImage().flush();
			hstate.setIcon(hPicture.getImageIcon());
			btnSetb.setEnabled(false);
		}
		
		
		
		if (e.getActionCommand().equals("reset")) {
			String hashType = (String) comboBox.getSelectedItem();
			if (hashType.equals("Triangle Hashing")) {
				setBElementsVisible(false, 7);
				hashTable = new TriangleHash(Integer.parseInt(formattedTextField_20.getText()));
				hPicture = new HashPicture(hashTable);
				textField.setText(hashTable.getSize()+"");
				textField_1.setText(hashTable.getFuellGrad());
				textField_2.setText(hPicture.getClusterNumber()+"");
				textField_3.setText("");
				ImageIcon icon = hPicture.getImageIcon();
		    	icon.getImage().flush();
				hstate.setIcon(hPicture.getImageIcon());
				
				System.out.println("jippie!");
			}
			
			if (hashType.equals("Universal Hashing")) {
				int p = Integer.parseInt(formattedTextField_19.getText());
				int m = Integer.parseInt(formattedTextField_20.getText());
				setBElementsVisible(false, 7);
				btnSetb.setEnabled(true);
				hashTable = new UniversellHash(m, p);
				hPicture = new HashPicture(hashTable);
				textField.setText(hashTable.getSize()+"");
				textField_1.setText(hashTable.getFuellGrad());
				textField_2.setText(hPicture.getClusterNumber()+"");
				textField_3.setText("");
				lblMax.setText(new String("0 - " + ( (int)Math.pow(2, (Integer.toBinaryString(m).length() -1)) -1)));
				ImageIcon icon = hPicture.getImageIcon();
		    	icon.getImage().flush();
				hstate.setIcon(hPicture.getImageIcon());
				setBElementsVisible(true, p+1);
				setBFields(hashTable.getHashvektorB());
				System.out.println("juhuu!");
			}
			
//			tHash = new TriangleHash(1024);
//			hPicture = new HashPicture(tHash);
//			textField.setText(tHash.getSize()+"");
//			textField_1.setText(tHash.getFuellGrad());
//			textField_2.setText(hPicture.getClusterNumber()+"");
//			textField_3.setText("");
//			ImageIcon icon = hPicture.getImageIcon();
//	    	icon.getImage().flush();
//			hstate.setIcon(hPicture.getImageIcon());
		}
		
		if (e.getActionCommand().equals("range")) {
			
			
			int koll = hashTable.addRange(Integer.parseInt(formattedTextField_4.getText()),
					Integer.parseInt(formattedTextField_5.getText()));
			textField.setText(hashTable.getSize()+"");
			textField_1.setText(hashTable.getFuellGrad());
			textField_2.setText(hPicture.getClusterNumber()+"");
			textField_3.setText(koll+"");
		  	ImageIcon icon = hPicture.getImageIcon();
	    	icon.getImage().flush();
			hstate.setIcon(hPicture.getImageIcon());
			btnSetb.setEnabled(false);
		}
		
		//random even von triangle hash
		if (e.getActionCommand().equals("random")) {
			int koll = hashTable.addManyRandom(Integer.parseInt(formattedTextField_1.getText()),
					Integer.parseInt(formattedTextField_2.getText()),
					Integer.parseInt(formattedTextField_3.getText()));
			textField.setText(hashTable.getSize()+"");
			textField_1.setText(hashTable.getFuellGrad());
			textField_2.setText(hPicture.getClusterNumber()+"");
			textField_3.setText(koll+"");
		  	ImageIcon icon = hPicture.getImageIcon();
	    	icon.getImage().flush();
			hstate.setIcon(hPicture.getImageIcon());
			btnSetb.setEnabled(false);
		}
		
		
		//random event mit intervallen
		if (e.getActionCommand().equals("randomIntervall")) {
			int [][] a = new int[4][3];
			
			a[0][0] = Integer.parseInt(formattedTextField_7.getText());
			a[0][1] = Integer.parseInt(formattedTextField_8.getText());
			a[0][2] = Integer.parseInt(formattedTextField_9.getText());
			a[1][0] = Integer.parseInt(formattedTextField_10.getText());
			a[1][1] = Integer.parseInt(formattedTextField_11.getText());
			a[1][2] = Integer.parseInt(formattedTextField_12.getText());
			a[2][0] = Integer.parseInt(formattedTextField_13.getText());
			a[2][1] = Integer.parseInt(formattedTextField_14.getText());
			a[2][2] = Integer.parseInt(formattedTextField_15.getText());
			a[3][0] = Integer.parseInt(formattedTextField_16.getText());
			a[3][1] = Integer.parseInt(formattedTextField_17.getText());
			a[3][2] = Integer.parseInt(formattedTextField_18.getText());

			int koll = hashTable.addManyRandomWithIntervalls(Integer.parseInt(formattedTextField_1.getText()),
					Integer.parseInt(formattedTextField_2.getText()),
					Integer.parseInt(formattedTextField_3.getText()), a);
			textField.setText(hashTable.getSize()+"");
			textField_1.setText(hashTable.getFuellGrad());
			textField_2.setText(hPicture.getClusterNumber()+"");
			textField_3.setText(koll+"");
		  	ImageIcon icon = hPicture.getImageIcon();
	    	icon.getImage().flush();
			hstate.setIcon(hPicture.getImageIcon());
			btnSetb.setEnabled(false);
			
		}
			
		if (e.getActionCommand().equals("setb")) {
			hashTable.setHashvektorB(getBVector(Integer.parseInt(formattedTextField_19.getText())+1));
		}
		
		if (e.getActionCommand().equals("suchen")) {
			String str = hashTable.suchen(Integer.parseInt(formattedTextField_6.getText()));
			textField_4.setText(str);
		}
	}
	
	
	/**
	 * Initialize the contents of the frame.
	 */
	private void initialize() {
		
		hashTable = new TriangleHash(1024);
		hPicture = new HashPicture(hashTable);
		frame = new JFrame();
		frame.setBounds(100, 100, 1051, 321);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.getContentPane().setLayout(null);
		
		hstate = new JLabel();
		hstate.setBounds(0, 188, 1024, 20);
		hstate.setIcon(hPicture.getImageIcon());
		frame.getContentPane().add(hstate);
		
		JButton button = new JButton("+");
		button.addActionListener(this);
		button.setActionCommand("plus1");
		button.setBounds(0, 89, 52, 25);
		button.setMnemonic(KeyEvent.VK_PLUS);
		frame.getContentPane().add(button);
		
		JLabel lblTableGreM = new JLabel("Anzahl");
		lblTableGreM.setHorizontalAlignment(SwingConstants.TRAILING);
		lblTableGreM.setBounds(87, 46, 39, 16);
		frame.getContentPane().add(lblTableGreM);
		
		formattedTextField = new JFormattedTextField();
		formattedTextField.setText("1");
		formattedTextField.setHorizontalAlignment(SwingConstants.TRAILING);
		formattedTextField.setBounds(0, 66, 61, 16);
		frame.getContentPane().add(formattedTextField);
		
		formattedTextField_1 = new JFormattedTextField();
		formattedTextField_1.setToolTipText("1");
		formattedTextField_1.setText("512");
		formattedTextField_1.setBounds(131, 46, 61, 16);
		frame.getContentPane().add(formattedTextField_1);
		
		formattedTextField_2 = new JFormattedTextField();
		formattedTextField_2.setText("1");
		formattedTextField_2.setBounds(131, 76, 61, 16);
		frame.getContentPane().add(formattedTextField_2);
		
		formattedTextField_3 = new JFormattedTextField();
		formattedTextField_3.setText("100000");
		formattedTextField_3.setBounds(131, 106, 61, 16);
		frame.getContentPane().add(formattedTextField_3);
		
		lblVon = new JLabel("von");
		lblVon.setHorizontalAlignment(SwingConstants.TRAILING);
		lblVon.setBounds(74, 76, 52, 16);
		frame.getContentPane().add(lblVon);
		
		lblBis = new JLabel("bis");
		lblBis.setHorizontalAlignment(SwingConstants.TRAILING);
		lblBis.setBounds(74, 105, 52, 16);
		frame.getContentPane().add(lblBis);
		
		final JButton btnFllen = new JButton("F\u00FCllen");
		btnFllen.addActionListener(this);
		btnFllen.setActionCommand("random");
		btnFllen.setBounds(97, 135, 95, 25);
		frame.getContentPane().add(btnFllen);
		
		JLabel lblZufallszahlen = new JLabel("Zufallszahlen");
		lblZufallszahlen.setBounds(77, 23, 115, 16);
		frame.getContentPane().add(lblZufallszahlen);
		
		JLabel lblEinzelneZahl = new JLabel("Einzelne Zahl");
		lblEinzelneZahl.setBounds(0, 46, 115, 16);
		frame.getContentPane().add(lblEinzelneZahl);
		
		JButton btnReset = new JButton("Reset");
		btnReset.addActionListener(this);
		btnReset.setActionCommand("reset");
		btnReset.setBounds(241, 219, 89, 23);
		frame.getContentPane().add(btnReset);
		
		JLabel lblBereich = new JLabel("Range");
		lblBereich.setBounds(464, 23, 117, 14);
		frame.getContentPane().add(lblBereich);
		
		JLabel lblStart = new JLabel("Start");
		lblStart.setHorizontalAlignment(SwingConstants.TRAILING);
		lblStart.setBounds(464, 45, 46, 14);
		frame.getContentPane().add(lblStart);
		
		JLabel lblEnde = new JLabel("Ende");
		lblEnde.setHorizontalAlignment(SwingConstants.TRAILING);
		lblEnde.setBounds(464, 76, 46, 14);
		frame.getContentPane().add(lblEnde);
		
		formattedTextField_4 = new JFormattedTextField();
		formattedTextField_4.setText("1");
		formattedTextField_4.setBounds(520, 44, 61, 16);
		frame.getContentPane().add(formattedTextField_4);
		
		formattedTextField_5 = new JFormattedTextField();
		formattedTextField_5.setText("1");
		formattedTextField_5.setBounds(520, 75, 61, 16);
		frame.getContentPane().add(formattedTextField_5);
		
		JButton button_1 = new JButton("F\u00FCllen");
		button_1.addActionListener(this);
		button_1.setActionCommand("range");
		button_1.setBounds(486, 135, 95, 25);
		frame.getContentPane().add(button_1);
		
		textField = new JTextField();
		textField.setHorizontalAlignment(SwingConstants.TRAILING);

		textField.setEditable(false);
		textField.setBounds(678, 44, 86, 16);
		frame.getContentPane().add(textField);
		textField.setColumns(10);
		
		JLabel lblAnzahlSchlssel = new JLabel("Anzahl Schl\u00FCssel");
		lblAnzahlSchlssel.setHorizontalAlignment(SwingConstants.TRAILING);
		lblAnzahlSchlssel.setBounds(566, 45, 103, 14);
		frame.getContentPane().add(lblAnzahlSchlssel);
		
		lblFllungsgrad = new JLabel("F\u00FCllungsgrad");
		lblFllungsgrad.setHorizontalAlignment(SwingConstants.TRAILING);
		lblFllungsgrad.setBounds(566, 67, 103, 14);
		frame.getContentPane().add(lblFllungsgrad);
		
		textField_1 = new JTextField();
		textField_1.setHorizontalAlignment(SwingConstants.TRAILING);
		textField_1.setEditable(false);
		textField_1.setBounds(678, 66, 86, 16);
		frame.getContentPane().add(textField_1);
		textField_1.setColumns(10);
		
		textField_2 = new JTextField();
		textField_2.setHorizontalAlignment(SwingConstants.TRAILING);
		textField_2.setEditable(false);
		textField_2.setBounds(678, 88, 86, 16);
		frame.getContentPane().add(textField_2);
		textField_2.setColumns(10);
		
		lblCluster = new JLabel("Cluster");
		lblCluster.setHorizontalAlignment(SwingConstants.TRAILING);
		lblCluster.setBounds(566, 89, 103, 14);
		frame.getContentPane().add(lblCluster);
		
		textField_3 = new JTextField();
		textField_3.setHorizontalAlignment(SwingConstants.TRAILING);
		textField_3.setEditable(false);
		textField_3.setColumns(10);
		textField_3.setBounds(678, 144, 86, 16);
		frame.getContentPane().add(textField_3);
		
		lblKollisionen = new JLabel("Kollisionen");
		lblKollisionen.setHorizontalAlignment(SwingConstants.TRAILING);
		lblKollisionen.setBounds(566, 145, 103, 14);
		frame.getContentPane().add(lblKollisionen);
		
		formattedTextField_6 = new JFormattedTextField();
		formattedTextField_6.setBounds(774, 46, 86, 16);
		frame.getContentPane().add(formattedTextField_6);
		
		btnSuchen = new JButton("Suchen");
		btnSuchen.addActionListener(this);
		btnSuchen.setActionCommand("suchen");
		btnSuchen.setBounds(870, 42, 95, 25);
		frame.getContentPane().add(btnSuchen);
		
		textField_4 = new JTextField();
		textField_4.setEditable(false);
		textField_4.setBounds(774, 77, 191, 20);
		frame.getContentPane().add(textField_4);
		textField_4.setColumns(10);
		
		final JCheckBox chckbxIntervalleBenutzen = new JCheckBox("Intervalle benutzen");
		chckbxIntervalleBenutzen.addItemListener(new ItemListener() {
			public void itemStateChanged(ItemEvent e) {
				if (chckbxIntervalleBenutzen == e.getItemSelectable()) {
					formattedTextField_7.setEnabled(true);
					formattedTextField_8.setEnabled(true);
					formattedTextField_9.setEnabled(true);
					formattedTextField_10.setEnabled(true);
					formattedTextField_11.setEnabled(true);
					formattedTextField_12.setEnabled(true);
					formattedTextField_13.setEnabled(true);
					formattedTextField_14.setEnabled(true);
					formattedTextField_15.setEnabled(true);
					formattedTextField_16.setEnabled(true);
					formattedTextField_17.setEnabled(true);
					formattedTextField_18.setEnabled(true);
					btnFllen.setActionCommand("randomIntervall");
					
				}
				if (ItemEvent.DESELECTED == e.getStateChange()) {
					formattedTextField_7.setEnabled(false);
					formattedTextField_8.setEnabled(false);
					formattedTextField_9.setEnabled(false);
					formattedTextField_10.setEnabled(false);
					formattedTextField_11.setEnabled(false);
					formattedTextField_12.setEnabled(false);
					formattedTextField_13.setEnabled(false);
					formattedTextField_14.setEnabled(false);
					formattedTextField_15.setEnabled(false);
					formattedTextField_16.setEnabled(false);
					formattedTextField_17.setEnabled(false);
					formattedTextField_18.setEnabled(false);
					btnFllen.setActionCommand("random");
				}
			}
			
		});
		chckbxIntervalleBenutzen.setBounds(198, 7, 132, 23);
		
		frame.getContentPane().add(chckbxIntervalleBenutzen);
		
		formattedTextField_7 = new JFormattedTextField();
		formattedTextField_7.setEnabled(false);
		formattedTextField_7.setHorizontalAlignment(SwingConstants.TRAILING);
		formattedTextField_7.setToolTipText("1");
		formattedTextField_7.setText("100");
		formattedTextField_7.setBounds(202, 46, 61, 16);
		frame.getContentPane().add(formattedTextField_7);
		
		formattedTextField_8 = new JFormattedTextField();
		formattedTextField_8.setEnabled(false);
		formattedTextField_8.setToolTipText("1");
		formattedTextField_8.setText("200");
		formattedTextField_8.setBounds(273, 46, 61, 16);
		frame.getContentPane().add(formattedTextField_8);
		
		formattedTextField_9 = new JFormattedTextField();
		formattedTextField_9.setEnabled(false);
		formattedTextField_9.setHorizontalAlignment(SwingConstants.TRAILING);
		formattedTextField_9.setToolTipText("1");
		formattedTextField_9.setText("20");
		formattedTextField_9.setBounds(344, 46, 29, 16);
		frame.getContentPane().add(formattedTextField_9);
		
		formattedTextField_10 = new JFormattedTextField();
		formattedTextField_10.setEnabled(false);
		formattedTextField_10.setHorizontalAlignment(SwingConstants.TRAILING);
		formattedTextField_10.setToolTipText("1");
		formattedTextField_10.setText("400");
		formattedTextField_10.setBounds(202, 76, 61, 16);
		frame.getContentPane().add(formattedTextField_10);
		
		formattedTextField_11 = new JFormattedTextField();
		formattedTextField_11.setEnabled(false);
		formattedTextField_11.setToolTipText("1");
		formattedTextField_11.setText("500");
		formattedTextField_11.setBounds(273, 76, 61, 16);
		frame.getContentPane().add(formattedTextField_11);
		
		formattedTextField_12 = new JFormattedTextField();
		formattedTextField_12.setEnabled(false);
		formattedTextField_12.setHorizontalAlignment(SwingConstants.TRAILING);
		formattedTextField_12.setToolTipText("1");
		formattedTextField_12.setText("20");
		formattedTextField_12.setBounds(344, 76, 29, 16);
		frame.getContentPane().add(formattedTextField_12);
		
		formattedTextField_13 = new JFormattedTextField();
		formattedTextField_13.setEnabled(false);
		formattedTextField_13.setHorizontalAlignment(SwingConstants.TRAILING);
		formattedTextField_13.setToolTipText("1");
		formattedTextField_13.setText("600");
		formattedTextField_13.setBounds(202, 106, 61, 16);
		frame.getContentPane().add(formattedTextField_13);
		
		formattedTextField_14 = new JFormattedTextField();
		formattedTextField_14.setEnabled(false);
		formattedTextField_14.setToolTipText("1");
		formattedTextField_14.setText("700");
		formattedTextField_14.setBounds(273, 106, 61, 16);
		frame.getContentPane().add(formattedTextField_14);
		
		formattedTextField_15 = new JFormattedTextField();
		formattedTextField_15.setEnabled(false);
		formattedTextField_15.setHorizontalAlignment(SwingConstants.TRAILING);
		formattedTextField_15.setToolTipText("1");
		formattedTextField_15.setText("20");
		formattedTextField_15.setBounds(344, 106, 29, 16);
		frame.getContentPane().add(formattedTextField_15);
		
		formattedTextField_16 = new JFormattedTextField();
		formattedTextField_16.setEnabled(false);
		formattedTextField_16.setHorizontalAlignment(SwingConstants.TRAILING);
		formattedTextField_16.setToolTipText("1");
		formattedTextField_16.setText("900");
		formattedTextField_16.setBounds(202, 135, 61, 16);
		frame.getContentPane().add(formattedTextField_16);
		
		formattedTextField_17 = new JFormattedTextField();
		formattedTextField_17.setEnabled(false);
		formattedTextField_17.setToolTipText("1");
		formattedTextField_17.setText("1000");
		formattedTextField_17.setBounds(273, 135, 61, 16);
		frame.getContentPane().add(formattedTextField_17);
		
		formattedTextField_18 = new JFormattedTextField();
		formattedTextField_18.setEnabled(false);
		formattedTextField_18.setHorizontalAlignment(SwingConstants.TRAILING);
		formattedTextField_18.setToolTipText("1");
		formattedTextField_18.setText("20");
		formattedTextField_18.setBounds(344, 135, 29, 16);
		frame.getContentPane().add(formattedTextField_18);
		
		JLabel label = new JLabel("-");
		label.setHorizontalAlignment(SwingConstants.CENTER);
		label.setBounds(262, 47, 13, 14);
		frame.getContentPane().add(label);
		
		JLabel label_1 = new JLabel("-");
		label_1.setHorizontalAlignment(SwingConstants.CENTER);
		label_1.setBounds(262, 77, 13, 14);
		frame.getContentPane().add(label_1);
		
		JLabel label_2 = new JLabel("-");
		label_2.setHorizontalAlignment(SwingConstants.CENTER);
		label_2.setBounds(262, 107, 13, 14);
		frame.getContentPane().add(label_2);
		
		JLabel label_3 = new JLabel("-");
		label_3.setHorizontalAlignment(SwingConstants.CENTER);
		label_3.setBounds(262, 135, 13, 14);
		frame.getContentPane().add(label_3);
		
		JLabel lblAnzteil = new JLabel("Anteil");
		lblAnzteil.setBounds(344, 25, 46, 14);
		frame.getContentPane().add(lblAnzteil);
		
		JLabel lblStart_1 = new JLabel("Start");
		lblStart_1.setHorizontalAlignment(SwingConstants.TRAILING);
		lblStart_1.setBounds(217, 30, 46, 14);
		frame.getContentPane().add(lblStart_1);
		
		JLabel lblEnde_1 = new JLabel("Ende");
		lblEnde_1.setBounds(273, 30, 46, 14);
		frame.getContentPane().add(lblEnde_1);
		
		JLabel label_4 = new JLabel("%");
		label_4.setBounds(375, 46, 46, 14);
		frame.getContentPane().add(label_4);
		
		JLabel label_5 = new JLabel("%");
		label_5.setBounds(375, 78, 46, 14);
		frame.getContentPane().add(label_5);
		
		JLabel label_6 = new JLabel("%");
		label_6.setBounds(375, 108, 46, 14);
		frame.getContentPane().add(label_6);
		
		JLabel label_7 = new JLabel("%");
		label_7.setBounds(375, 136, 46, 14);
		frame.getContentPane().add(label_7);
//		
//		JComboBox comboBox = new JComboBox();
//		comboBox.setBounds(805, 250, 86, 20);
//		frame.getContentPane().add(comboBox);
		

		comboBox = new JComboBox<String>();
		comboBox.addItem("Triangle Hashing");
		comboBox.addItem("Universal Hashing");
		comboBox.addActionListener(this);
		comboBox.setBounds(10, 219, 149, 20);
		frame.getContentPane().add(comboBox);
		
		formattedTextField_19 = new JFormattedTextField();
		formattedTextField_19.setHorizontalAlignment(SwingConstants.TRAILING);
		formattedTextField_19.setText("2");
		formattedTextField_19.setBounds(170, 249, 61, 16);
		frame.getContentPane().add(formattedTextField_19);
		
		formattedTextField_20 = new JFormattedTextField();
		formattedTextField_20.setHorizontalAlignment(SwingConstants.TRAILING);
		formattedTextField_20.setText("1024");
		formattedTextField_20.setBounds(170, 222, 61, 16);
		frame.getContentPane().add(formattedTextField_20);
		
		formattedTextField_21 = new JFormattedTextField();
		formattedTextField_21.setText("2");
		formattedTextField_21.setVisible(false);
		formattedTextField_21.setHorizontalAlignment(SwingConstants.TRAILING);
		formattedTextField_21.setBounds(398, 222, 61, 16);
		frame.getContentPane().add(formattedTextField_21);
		
		formattedTextField_22 = new JFormattedTextField();
		formattedTextField_22.setText("2");
		formattedTextField_22.setVisible(false);
		formattedTextField_22.setHorizontalAlignment(SwingConstants.TRAILING);
		formattedTextField_22.setBounds(464, 222, 61, 16);
		frame.getContentPane().add(formattedTextField_22);
		
		formattedTextField_23 = new JFormattedTextField();
		formattedTextField_23.setText("2");
		formattedTextField_23.setVisible(false);
		formattedTextField_23.setHorizontalAlignment(SwingConstants.TRAILING);
		formattedTextField_23.setBounds(530, 222, 61, 16);
		frame.getContentPane().add(formattedTextField_23);
		
		formattedTextField_24 = new JFormattedTextField();
		formattedTextField_24.setText("2");
		formattedTextField_24.setVisible(false);
		formattedTextField_24.setHorizontalAlignment(SwingConstants.TRAILING);
		formattedTextField_24.setBounds(595, 222, 61, 16);
		frame.getContentPane().add(formattedTextField_24);
		
		formattedTextField_25 = new JFormattedTextField();
		formattedTextField_25.setText("2");
		formattedTextField_25.setVisible(false);
		formattedTextField_25.setHorizontalAlignment(SwingConstants.TRAILING);
		formattedTextField_25.setBounds(661, 222, 61, 16);
		frame.getContentPane().add(formattedTextField_25);
		
		formattedTextField_26 = new JFormattedTextField();
		formattedTextField_26.setText("2");
		formattedTextField_26.setVisible(false);
		formattedTextField_26.setHorizontalAlignment(SwingConstants.TRAILING);
		formattedTextField_26.setBounds(727, 222, 61, 16);
		frame.getContentPane().add(formattedTextField_26);
		
		formattedTextField_27 = new JFormattedTextField();
		formattedTextField_27.setText("2");
		formattedTextField_27.setVisible(false);
		formattedTextField_27.setHorizontalAlignment(SwingConstants.TRAILING);
		formattedTextField_27.setBounds(793, 222, 61, 16);
		frame.getContentPane().add(formattedTextField_27);
		
		btnSetb = new JButton("Set b");
		btnSetb.setBounds(429, 250, 89, 23);
		btnSetb.addActionListener(this);
		btnSetb.setActionCommand("setb");
		btnSetb.setVisible(false);
		frame.getContentPane().add(btnSetb);
		
		lblMax = new JLabel("max ");
		lblMax.setBounds(540, 254, 207, 14);
		lblMax.setVisible(false);
		frame.getContentPane().add(lblMax);
	}
	
	private void setBElementsVisible(Boolean bool, int n) {
		
		switch (n) {
		
		case 7 : formattedTextField_27.setVisible(bool);
		case 6 : formattedTextField_26.setVisible(bool);
		case 5 : formattedTextField_25.setVisible(bool);
		case 4 : formattedTextField_24.setVisible(bool);
		case 3 : formattedTextField_23.setVisible(bool);
		case 2 : formattedTextField_22.setVisible(bool);
		case 1 : formattedTextField_21.setVisible(bool);
					lblMax.setVisible(bool);
					btnSetb.setVisible(bool);
		}
	}
	
	private void setBFields(int[] hashVectorB) {
		switch (hashVectorB.length) {
		case 7 : formattedTextField_27.setText(hashVectorB[6] + "");
		case 6 : formattedTextField_26.setText(hashVectorB[5] + "");
		case 5 : formattedTextField_25.setText(hashVectorB[4] + "");
		case 4 : formattedTextField_24.setText(hashVectorB[3] + "");
		case 3 : formattedTextField_23.setText(hashVectorB[2] + "");
		case 2 : formattedTextField_22.setText(hashVectorB[1] + "");
		case 1 : formattedTextField_21.setText(hashVectorB[0] + "");
		}
	}
	
	private int[] getBVector(int c) {
		int[] b = new int[c];
		
		switch (c) {
		case 7 : b[6] = Integer.parseInt(formattedTextField_27.getText());
		case 6 : b[5] = Integer.parseInt(formattedTextField_26.getText());
		case 5 : b[4] = Integer.parseInt(formattedTextField_25.getText());
		case 4 : b[3] = Integer.parseInt(formattedTextField_24.getText());
		case 3 : b[2] = Integer.parseInt(formattedTextField_23.getText());
		case 2 : b[1] = Integer.parseInt(formattedTextField_22.getText());
		case 1 : b[0] = Integer.parseInt(formattedTextField_21.getText());
		}
		
		return b;
	}
}
